﻿
using Microsoft.Extensions.DependencyInjection;
using StormCoding.DIExtensions.Selector;

namespace StormCoding.DIExtensions
{
    public static partial class ServiceCollectionExtensions
    {
        public static IServiceCollection Scan(this IServiceCollection services, Action<ITypeSelector> action) 
        {
            var selector = new TypeSelector();
            action(selector);
            return services.Register(selector, RegistrationBehavior.Append);
        }
        public static IServiceCollection Register(this IServiceCollection services, ISelector selector, RegistrationBehavior behavior) {
            selector.Register(services, behavior);
            return services;
        }
        /// <summary>
        /// 服务是否已经注册
        /// </summary>
        /// <param name="services"></param>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        public static bool HasRegistration(this IServiceCollection services, Type serviceType) 
        {
            return services.Any(x => x.ServiceType == serviceType);
        }

    }
}
